﻿CREATE PROCEDURE [RestartFramework].[RemoveETLJobStage]
		@pETLJobName			SYSNAME
,		@pETLJobStageName		SYSNAME
,		@pRemovedJobStagesTally	SMALLINT	=	NULL OUTPUT
,       @pPrint                 BIT         =   1
AS
BEGIN
		SET NOCOUNT ON;
		DELETE
		FROM	[RestartFramework].[ETLJobStage]
		WHERE	[ETLJobStageName]	=	@pETLJobStageName
			AND	[ETLJobId]			=	(	SELECT	ej.[ETLJobId]
											FROM	[RestartFramework].[ETLJob] ej
											WHERE	ej.[ETLJobName] = @pETLJobName
										);
		SET	@pRemovedJobStagesTally = @@ROWCOUNT;
		IF(@pPrint = 1)
				PRINT   CONVERT(NVARCHAR(5),@pRemovedJobStagesTally) + N' rows deleted from [RestartFramework].[ETLJobStage] for ETLJobName=' + @pETLJobName + N', ETLJobStageName=' + @pETLJobStageName ;
END
